package com.cdream.basic.algorithm.leetcode.tree;

public class Question112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        // 判断是否是叶子节点
        if (root.left==null && root.right==null){
            return targetSum == root.val;
        }
        return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);
    }
}
